﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract GrupaDjelatnikParametra typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class GrupaDjelatnikParametraDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<GrupaDjelatnikParametraDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.GrupaDjelatnikParametra _currentGrupaDjelatnikParametra = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxGrupaDjelatnikParametraDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxGrupaDjelatnikParametraErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxGrupaDjelatnikParametraBindingSource;
		
		/// <summary> 
		/// the DGV column associated with the IDGrupaDjelatnik property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDGrupaDjelatnikDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the IDGrupaParemetra property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDGrupaParemetraDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.GrupaDjelatnik> _IDGrupaDjelatnikList;
		
		/// <summary> 
		/// The list of selectable GrupaDjelatnik
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.GrupaDjelatnik> IDGrupaDjelatnikList
		{
			get {return this._IDGrupaDjelatnikList;}
			set 
			{
				this._IDGrupaDjelatnikList = value;
				this.uxIDGrupaDjelatnikDataGridViewColumn.DataSource = null;
				this.uxIDGrupaDjelatnikDataGridViewColumn.DataSource = this._IDGrupaDjelatnikList;
			}
		}
		
		private bool _allowNewItemInIDGrupaDjelatnikList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of GrupaDjelatnik
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDGrupaDjelatnikList
		{
			get { return _allowNewItemInIDGrupaDjelatnikList;}
			set
			{
				this._allowNewItemInIDGrupaDjelatnikList = value;
				this.uxIDGrupaDjelatnikDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
				
		private Entities.TList<Entities.GrupaParametra> _IDGrupaParemetraList;
		
		/// <summary> 
		/// The list of selectable GrupaParametra
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.GrupaParametra> IDGrupaParemetraList
		{
			get {return this._IDGrupaParemetraList;}
			set 
			{
				this._IDGrupaParemetraList = value;
				this.uxIDGrupaParemetraDataGridViewColumn.DataSource = null;
				this.uxIDGrupaParemetraDataGridViewColumn.DataSource = this._IDGrupaParemetraList;
			}
		}
		
		private bool _allowNewItemInIDGrupaParemetraList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of GrupaParametra
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDGrupaParemetraList
		{
			get { return _allowNewItemInIDGrupaParemetraList;}
			set
			{
				this._allowNewItemInIDGrupaParemetraList = value;
				this.uxIDGrupaParemetraDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.GrupaDjelatnikParametra> _GrupaDjelatnikParametraList;
				
		/// <summary> 
		/// The list of GrupaDjelatnikParametra to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.GrupaDjelatnikParametra> GrupaDjelatnikParametraList
		{
			get {return this._GrupaDjelatnikParametraList;}
			set
			{
				this._GrupaDjelatnikParametraList = value;
				this.uxGrupaDjelatnikParametraBindingSource.DataSource = null;
				this.uxGrupaDjelatnikParametraBindingSource.DataSource = value;
				this.uxGrupaDjelatnikParametraDataGridView.DataSource = null;
				this.uxGrupaDjelatnikParametraDataGridView.DataSource = this.uxGrupaDjelatnikParametraBindingSource;				
				//this.uxGrupaDjelatnikParametraBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxGrupaDjelatnikParametraBindingSource_ListChanged);
				this.uxGrupaDjelatnikParametraBindingSource.CurrentItemChanged += new System.EventHandler(OnGrupaDjelatnikParametraBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnGrupaDjelatnikParametraBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentGrupaDjelatnikParametra = uxGrupaDjelatnikParametraBindingSource.Current as Entities.GrupaDjelatnikParametra;
			
			if (_currentGrupaDjelatnikParametra != null)
			{
				_currentGrupaDjelatnikParametra.Validate();
			}
			//_GrupaDjelatnikParametra.Validate();
			OnCurrentEntityChanged();
		}

		//void uxGrupaDjelatnikParametraBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.GrupaDjelatnikParametra"/> instance.
		/// </summary>
		public Entities.GrupaDjelatnikParametra SelectedGrupaDjelatnikParametra
		{
			get {return this._currentGrupaDjelatnikParametra;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxGrupaDjelatnikParametraDataGridView.VirtualMode;}
			set
			{
				this.uxGrupaDjelatnikParametraDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxGrupaDjelatnikParametraDataGridView.AllowUserToAddRows;}
			set {this.uxGrupaDjelatnikParametraDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxGrupaDjelatnikParametraDataGridView.AllowUserToDeleteRows;}
			set {this.uxGrupaDjelatnikParametraDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxGrupaDjelatnikParametraDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxGrupaDjelatnikParametraDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="GrupaDjelatnikParametraDataGridViewBase"/> class.
		/// </summary>
		public GrupaDjelatnikParametraDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxGrupaDjelatnikParametraDataGridView = new System.Windows.Forms.DataGridView();
			this.uxGrupaDjelatnikParametraBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxGrupaDjelatnikParametraErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDGrupaDjelatnikDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxIDGrupaParemetraDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			//this.uxIDGrupaDjelatnikBindingSource = new GrupaDjelatnikBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDGrupaDjelatnikBindingSource)).BeginInit();
			//this.uxIDGrupaParemetraBindingSource = new GrupaParametraBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDGrupaParemetraBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGrupaDjelatnikParametraDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGrupaDjelatnikParametraBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGrupaDjelatnikParametraErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxGrupaDjelatnikParametraErrorProvider
			// 
			this.uxGrupaDjelatnikParametraErrorProvider.ContainerControl = this;
			this.uxGrupaDjelatnikParametraErrorProvider.DataSource = this.uxGrupaDjelatnikParametraBindingSource;						
			// 
			// uxGrupaDjelatnikParametraDataGridView
			// 
			this.uxGrupaDjelatnikParametraDataGridView.AutoGenerateColumns = false;
			this.uxGrupaDjelatnikParametraDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxGrupaDjelatnikParametraDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDGrupaDjelatnikDataGridViewColumn,
		this.uxIDGrupaParemetraDataGridViewColumn			});
			this.uxGrupaDjelatnikParametraDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxGrupaDjelatnikParametraDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxGrupaDjelatnikParametraDataGridView.Name = "uxGrupaDjelatnikParametraDataGridView";
			this.uxGrupaDjelatnikParametraDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxGrupaDjelatnikParametraDataGridView.TabIndex = 0;	
			this.uxGrupaDjelatnikParametraDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxGrupaDjelatnikParametraDataGridView.EnableHeadersVisualStyles = false;
			this.uxGrupaDjelatnikParametraDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnGrupaDjelatnikParametraDataGridViewDataError);
			this.uxGrupaDjelatnikParametraDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnGrupaDjelatnikParametraDataGridViewCellValueNeeded);
			this.uxGrupaDjelatnikParametraDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnGrupaDjelatnikParametraDataGridViewCellValuePushed);
			
			//
			// uxIDGrupaDjelatnikDataGridViewColumn
			//
			this.uxIDGrupaDjelatnikDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDGrupaDjelatnikDataGridViewColumn.DataPropertyName = "IDGrupaDjelatnik";
			this.uxIDGrupaDjelatnikDataGridViewColumn.HeaderText = "IDGrupaDjelatnik";
			this.uxIDGrupaDjelatnikDataGridViewColumn.Name = "uxIDGrupaDjelatnikDataGridViewColumn";
			this.uxIDGrupaDjelatnikDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDGrupaDjelatnikDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDGrupaDjelatnikDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDGrupaParemetraDataGridViewColumn
			//
			this.uxIDGrupaParemetraDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDGrupaParemetraDataGridViewColumn.DataPropertyName = "IDGrupaParemetra";
			this.uxIDGrupaParemetraDataGridViewColumn.HeaderText = "IDGrupaParemetra";
			this.uxIDGrupaParemetraDataGridViewColumn.Name = "uxIDGrupaParemetraDataGridViewColumn";
			this.uxIDGrupaParemetraDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDGrupaParemetraDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDGrupaParemetraDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDGrupaDjelatnikDataGridViewColumn
			//				
			this.uxIDGrupaDjelatnikDataGridViewColumn.DisplayMember = "Naziv";	
			this.uxIDGrupaDjelatnikDataGridViewColumn.ValueMember = "ID";	
			this.uxIDGrupaDjelatnikDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDGrupaDjelatnikDataGridViewColumn.DataSource = uxIDGrupaDjelatnikBindingSource;				
				
			//
			// uxIDGrupaParemetraDataGridViewColumn
			//				
			this.uxIDGrupaParemetraDataGridViewColumn.DisplayMember = "Naziv";	
			this.uxIDGrupaParemetraDataGridViewColumn.ValueMember = "IDGrupaParametra";	
			this.uxIDGrupaParemetraDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDGrupaParemetraDataGridViewColumn.DataSource = uxIDGrupaParemetraBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxGrupaDjelatnikParametraDataGridView);
			this.Name = "GrupaDjelatnikParametraDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDGrupaDjelatnikBindingSource)).EndInit();
			//((System.ComponentModel.ISupportInitialize)(this.uxIDGrupaParemetraBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGrupaDjelatnikParametraErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGrupaDjelatnikParametraDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGrupaDjelatnikParametraBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				GrupaDjelatnikParametraDataGridViewEventArgs args = new GrupaDjelatnikParametraDataGridViewEventArgs();
				args.GrupaDjelatnikParametra = _currentGrupaDjelatnikParametra;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class GrupaDjelatnikParametraDataGridViewEventArgs : System.EventArgs
		{
			private Entities.GrupaDjelatnikParametra	_GrupaDjelatnikParametra;
	
			/// <summary>
			/// the  Entities.GrupaDjelatnikParametra instance.
			/// </summary>
			public Entities.GrupaDjelatnikParametra GrupaDjelatnikParametra
			{
				get { return _GrupaDjelatnikParametra; }
				set { _GrupaDjelatnikParametra = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxGrupaDjelatnikParametraDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnGrupaDjelatnikParametraDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxGrupaDjelatnikParametraDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnGrupaDjelatnikParametraDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxGrupaDjelatnikParametraDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDGrupaDjelatnikDataGridViewColumn":
						e.Value = GrupaDjelatnikParametraList[e.RowIndex].IDGrupaDjelatnik;
						break;
					case "uxIDGrupaParemetraDataGridViewColumn":
						e.Value = GrupaDjelatnikParametraList[e.RowIndex].IDGrupaParemetra;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxGrupaDjelatnikParametraDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnGrupaDjelatnikParametraDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxGrupaDjelatnikParametraDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDGrupaDjelatnikDataGridViewColumn":
						GrupaDjelatnikParametraList[e.RowIndex].IDGrupaDjelatnik = (System.Int32)e.Value;
						break;
					case "uxIDGrupaParemetraDataGridViewColumn":
						GrupaDjelatnikParametraList[e.RowIndex].IDGrupaParemetra = (System.Int32)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
